#include "bsp_uart.h"

void UartBspUart5Send(uint8_t *tx_data,uint16_t tx_len)
{
	for(uint16_t i = 0;i < tx_len;i++)
	{
		FL_UART_WriteTXBuff(UART5,tx_data[i]);
		while(!FL_UART_IsActiveFlag_TXBuffEmpty(UART5));
	}
}

static void UartBspUart5Init(void)
{
	FL_NVIC_ConfigTypeDef    InterruptConfigStruct;
	FL_UART_InitTypeDef    UART5_InitStruct = {0};

	UART5_InitStruct.clockSrc          = FL_CMU_UART0_CLK_SOURCE_APBCLK;
	UART5_InitStruct.baudRate          = 115200;
	UART5_InitStruct.transferDirection = FL_UART_DIRECTION_TX_RX;
	UART5_InitStruct.dataWidth         = FL_UART_DATA_WIDTH_8B;
	UART5_InitStruct.stopBits          = FL_UART_STOP_BIT_WIDTH_1B;
	UART5_InitStruct.parity            = FL_UART_PARITY_NONE;

	(void)FL_UART_Init(UART5, &UART5_InitStruct);
	
	FL_UART_ClearFlag_RXBuffFull(UART5);
	FL_UART_EnableIT_RXBuffFull(UART5);

//	FL_UART_ClearFlag_TXShiftBuffEmpty(UART5);
//	FL_UART_EnableIT_TXShiftBuffEmpty(UART5);

	InterruptConfigStruct.preemptPriority = 0x02;
	FL_NVIC_Init(&InterruptConfigStruct, UART5_IRQn);
	UartBspUart5Send((uint8_t *)"boot run",8u);
}

void UartBspDeinit(void)
{
	FL_UART_DeInit(UART5);
}

void UartBspInit(void)
{   	
	UartBspUart5Init();
}
